# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Kevin Daudt <kdaudt@alpinelinux.org>
pkgname=postsrsd
pkgver=2.0.8
pkgrel=0
pkgdesc="Postfix Sender Rewriting Scheme daemon"
url="https://github.com/roehling/postsrsd"
arch="all"
license="GPL-3.0-only AND BSD-3-Clause AND FSFUL"
makedepends="
	autoconf
	automake
	confuse-dev
	cmake
	help2man
	samurai
	sqlite-dev
	"
#checkdepends="subunit-dev"
pkgusers="postsrsd"
install="$pkgname.pre-install postsrsd.pre-upgrade"
subpackages="$pkgname-doc $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/roehling/postsrsd/archive/$pkgver.tar.gz
	postsrsd-conf-change-defaults.patch
	postsrsd.initd
	"

# secfixes:
#   1.6-r4:
#     - CVE-2020-35573

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS \
		-DCMAKE_INSTALL_PREFIX=/usr/ \
		-DWITH_SQLITE=ON \
		-DTESTS_WITH_ASAN=OFF \
		-DGENERATE_SRS_SECRET=OFF \
		-DPOSTSRSD_CONFIGDIR=/etc/postsrsd/ \
		-DINSTALL_SYSTEMD_SERVICE=OFF \
		-DPOSTSRSD_USER=postsrsd
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm0644 build/postsrsd.conf -t "$pkgdir"/etc/postsrsd/
	install -Dm0755 "$srcdir"/postsrsd.initd "$pkgdir"/etc/init.d/postsrsd
}

sha512sums="
6f21b194890afad11f0c131ef892227bef536fabbd9b1add2b5d6994b3d2f7391e489aa84fb8c0dcb3ffb936e1073f09ff7d9382a1cbf240887857f37f13e3db  postsrsd-2.0.8.tar.gz
affa7e7ab165e2c11c8e32bd4638d29f371fc1d0f38c6eaf4d0b6853de384bda199e238067b70e7ccf9bc55859e54f76b978c461d6feb6f45b98667643ee8b6f  postsrsd-conf-change-defaults.patch
213a45f07de7f45ddbfaa905a80682ac7a9762d6f0c62b11101aaeee07a7ffe802a392dc1a97389adfed7ca16e8268ad0dc20e99b8501a9a7c21736dca79a7e1  postsrsd.initd
"
